import {
	getInternalCode,
	getExternalCode
} from './codeFun'

const data = [{
		code: 1,
		count: 1,
		internal: true,
		content: '你的自我管理能力不错',
	},
	{
		code: 1,
		count: 2,
		internal: true,
		content: '你的自我管理能力不错，而且眼里有活，性能力旺盛',
	},
	{
		code: 1,
		count: 3,
		internal: true,
		bottomBoth: false,
		content: '你的自我管理能力不错，而且眼里有活，家人对你的认可度也很高，嘴上不说，心里经常会嫌别人笨，性能力旺盛',
	},
	{
		code: 1,
		count: 3,
		internal: true,
		bottomBoth: true,
		content: '你的自我管理能力不错，而且眼里有活，家人对你的认可度也很高，嘴上不说，心里经常会嫌别人笨，你身上会有疤痕，性能力旺盛',
	},
	{
		code: 2,
		internal: true,
		external: true,
		content: '你善于社交，喜欢享受亲密关系，内心温柔浪漫',
	},
	{
		code: 2,
		internal: true,
		external: false,
		content: '你内心温柔浪漫，跟熟人在一起很爱说话，跟生人不太喜欢说话',
	},
	{
		code: 2,
		internal: false,
		external: true,
		content: '你在家里说话比较少，更多的是需要对方的一种有默契的感觉，自己还没有说，对方就知道自的想法',
	},
	{
		code: 2,
		internal: false,
		external: false,
		content: '你通常不直接说出自己的真实想法，喜欢让别人猜',
	},
	{
		code: 3,
		code2: 8,
		hasInternalCode: true,
		hasInternalCode2: false,
		content: '你热情活泼，脾气来的快去的也快，每天你都会为小事着急上火',
	},
	{
		code: 3,
		code2: 8,
		hasInternalCode: false,
		hasInternalCode2: true,
		content: '你平时不轻易发火，一旦发火天崩地裂，发火前可能会有预兆，只要有事，睡眠就不好',
	},
	{
		code: 3,
		code2: 8,
		hasInternalCode: true,
		hasInternalCode2: true,
		content: '你热情活泼，对过往的事情会很在意，遇大事一开始你会慌神，很快就会沉稳下来，但是小事会让你生气，只要有事，睡眠就不好',
	},
	{
		code: 3,
		code2: 8,
		hasInternalCode: false,
		hasInternalCode2: false,
		content: '你会给别人情绪变化无常的感觉',
	},
	{
		code: 2,
		code2: 7,
		hasInternalCode: true,
		hasInternalCode2: true,
		content: '喜欢小资生活',
	},
	{
		code: 4,
		internal: true,
		external: false,
		content: '你喜欢看一些自己感兴趣的书，比较缺乏安全感，爱意只表现给自己喜欢的人',
	},
	{
		code: 4,
		count: 2,
		internal: true,
		external: false,
		content: '你喜欢看一些自己感兴趣的书，在做任何事情的时候，你都会有两个方案，缺乏安全感，爱意只表现给自己喜欢的人',
	},
	{
		code: 4,
		internal: false,
		external: true,
		content: '你喜欢看一些专业类的，或者是和自己工作有关的书',
	},
	{
		code: 4,
		internal: false,
		external: false,
		content: '你不怎么喜欢看书，一看书就让你犯困',
	},
	{
		code: 4,
		internal: true,
		external: true,
		content: '你学习力强，缺乏安全感，喜欢看书，爱意只表现给自己喜欢的人',
	},
	{
		code: 5,
		internal: true,
		external: true,
		content: '你热情活泼，是一个方向感很强，爱自由的人，不喜欢受约束',
	},
	{
		code: 5,
		internal: true,
		external: false,
		content: '你热情活泼，是一个方向感很强，爱自由的人，不喜欢受约束',
	},
	{
		code: 5,
		internal: false,
		external: true,
		content: '方向感不强，不认路，容易迷失，建议你找个导师为自己的人生引导和规划，开阔自己的眼界',
	},
	{
		code: 6,
		internal: true,
		external: true,
		content: '你的感情细腻温和',
	},
	{
		code: 6,
		internal: true,
		external: false,
		content: '你的感情细腻温和',
	},
	{
		code: 6,
		internal: false,
		external: true,
		content: '你的财富来自于自己的创造和打拼，而原生家庭无法为你提供太多的帮助',
	},
	{
		code: 7,
		internal: true,
		external: true,
		content: '你的运气好到爆，但是比较懒，只有不得不做的时候才会去做，身边的朋友很多，得到你认可的好朋友屈指可数',
	},
	{
		code: 7,
		internal: true,
		external: false,
		content: '你的贵人缘很好，且是来自于家庭或者很好的朋友，身边的朋友很多，得到你认可的好朋友屈指可数',
	},
	{
		code: 7,
		internal: false,
		external: true,
		content: '你是一个热心人，就是经常喜欢帮别人忙，但是轮到自己有困难的时候了，反而没有很多人来帮你',
	},
	{
		code: 9,
		internal: true,
		external: true,
		content: '家人和领导对你的认可度都很高，思维活跃、发散，变化较多，很会照顾人',
	},
	{
		code: 9,
		internal: true,
		external: false,
		content: '你很会照顾人，很容易得到家人的认可，浪漫，多变',
	},
	{
		code: 9,
		internal: false,
		external: true,
		content: '在工作上你的领导和同事都对你比较认可',
	},
]

const fun = {
	count(internalCode, externalCode, {
		code
	}) {
		const count = internalCode.filter((el) => el === code).length
		return Math.min(count, 3)
	},
	bottomBoth(internalCode, externalCode, {
		code
	}) {
		const count = internalCode.slice(3).filter((el) => el === code).length
		return count >= 3
	},
	internal(internalCode, externalCode, {
		code
	}) {
		return internalCode.includes(code)
	},
	external(internalCode, externalCode, {
		code
	}) {
		return externalCode.includes(code)
	},
	hasCode(internalCode, externalCode, {
		code
	}) {
		return internalCode.includes(code) || externalCode.includes(code)
	},
	hasInternalCode(internalCode, externalCode, {
		code
	}) {
		return internalCode.includes(code)
	},
	hasInternalCode2(internalCode, externalCode, {
		code2
	}) {
		return internalCode.includes(code2)
	},
	hasCode2(internalCode, externalCode, {
		code2
	}) {
		return internalCode.includes(code2) || externalCode.includes(code2)
	},
}
const data2 = [{
		code: 1,
		condition: ['count', 'internal'],
	},
	{
		code: 1,
		condition: ['count', 'internal', 'bottomBoth'],
	},
	{
		code: 2,
		condition: ['internal', 'external'],
	},
	{
		code: 3,
		code2: 8,
		condition: ['hasInternalCode', 'hasInternalCode2'],
	},
	{
		code: 2,
		code2: 7,
		condition: ['hasInternalCode', 'hasInternalCode2'],
	},
	{
		code: 4,
		condition: ['internal', 'external'],
	},
	{
		code: 4,
		condition: ['count', 'internal'],
	},
	{
		code: 5,
		condition: ['internal', 'external'],
	},
	{
		code: 6,
		condition: ['internal', 'external'],
	},
	{
		code: 7,
		condition: ['internal', 'external'],
	},
	{
		code: 9,
		condition: ['internal', 'external'],
	},
]

export function getInternalExternalCodeContent(birthday) {
	const internalCode = getInternalCode(birthday)
	const externalCode = getExternalCode(birthday)
	const allCode = [...new Set([...internalCode, ...externalCode])]
	const result = data2.filter(el => allCode.includes(el.code)).map((el) => {
		const obj = {
			code: el.code
		}
		if (el.code2) {
			obj.code2 = el.code2
		}
		for (const prop of el.condition) {
			obj[prop] = fun[prop](internalCode, externalCode, el)
		}
		return obj
	})
	const resultContent = result.map((el) => {
		const keys = Object.keys(el)
		return data.find((i) => {
			const keys2 = Object.keys(i).filter(el => el != 'content')
			return keys2.length === keys.length && keys.every((key) => el[key] === i[key])
		})
	})
	return resultContent.filter(el => el)
}
